package com.java.tutorials.jdk7.currency;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;

/**
 * Created by xuzhike on 2016/1/23.
 * http://www.java2s.com/Code/Java/JDK-7/Formatcurrency.htm
 */
public class CurrencyTest2 {
    public static void main(String[] args) {
        BigDecimal value = new BigDecimal(12345);
        Locale.setDefault(Locale.JAPAN);
        System.out.printf("Default locale: %s\n", Locale.getDefault()
                .getDisplayName());
        NumberFormat nf = NumberFormat.getCurrencyInstance();
        String formattedCurrency = nf.format(value);
        System.out.printf("%s\n", formattedCurrency);
        nf.setCurrency(Currency.getInstance(Locale.US));
        formattedCurrency = nf.format(value);
        System.out.printf("%s\n\n", formattedCurrency);

        Locale.setDefault(Locale.US);
        System.out.printf("Default locale: %s\n", Locale.getDefault()
                .getDisplayName());
        nf = NumberFormat.getCurrencyInstance();
        formattedCurrency = nf.format(value);
        System.out.printf("%s\n", formattedCurrency);
        nf.setCurrency(Currency.getInstance("JPY"));
        formattedCurrency = nf.format(value);
        System.out.printf("%s\n\n", formattedCurrency);

        Locale.setDefault(Locale.FRANCE);
        System.out.printf("Default locale: %s\n", Locale.getDefault()
                .getDisplayName());
        nf = NumberFormat.getCurrencyInstance();
        formattedCurrency = nf.format(value);
        System.out.printf("%s\n", formattedCurrency);
        nf.setCurrency(Currency.getInstance("USD"));
        formattedCurrency = nf.format(value);
        System.out.printf("%s\n\n", formattedCurrency);
    }
}
